<?php

namespace App\Http\Controllers\Admin;

use App\Models\Index\LiveAmuse;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class LiveAmuseController extends Controller
{
    public function getAmuseList(Request $request)
    {
        $data = LiveAmuse::getAmuseListAndPaginate();
        return self::response($data,200);
    }

    /**
     * 新增/修改 配置
     * @param Request $request
     * @return mixed
     */
    public function modifyAmuse(Request $request)
    {
        $input = $request->all();

        if (empty($input['id'])){
            if (empty($input['title'])){
                return self::response(null,'-1','title is null');
            }
            if (empty($input['img'])){
                return self::response(null,'-1','img is null');
            }

            if (empty($input['url'])){
                return self::response(null,'-1','url is null');
            }

            if (empty($input['cate_id'])){
                return self::response(null,'-1','cate_id is null');
            }
            unset($input['id']);
            $input['created_time'] = time();
            $input = Controller::createData('live_amuse',$input);
            $flag = LiveAmuse::query()->insert($input);
            $msg  = '新增';
        }else{
            if (empty($input)){
                return self::response(null,'-1','请选择修改项');
            }
            $input['created_time'] = time();
            $input = Controller::createData('live_amuse',$input);
            $flag = LiveAmuse::query()->where('id',$input['id'])->update($input);
            $msg  = '修改';
        }
        if ($flag){
            return self::response(null,200,$msg.'成功');
        }else{
            return self::response(null,-1,$msg.'失败');
        }
    }


    public function del(Request $request)
    {
        $input = $request->all();
        if (empty($input['id'])){
            return self::response(null,'-1','请选择删除项');
        }
        $flag = LiveAmuse::query()->where('id',$input['id'])->delete();
        if ($flag !==false){
            return self::response(null,200,'删除成功');
        }else{
            return self::response(null,-1,'删除失败');
        }
    }
}
